package com.ctgu.tengyun.bean.convert;

import com.ctgu.tengyun.bean.response.FileTemplateListResponse;
import com.ctgu.tengyun.domain.FileTemplate;

import java.util.List;

/**
 * Created by liaoweizhi on 2019/8/6.
 */
public class FileTemplateConvert {

    public static FileTemplateListResponse toFileTemplateListResponse(Integer totalCount,
                                                                      Integer pageSize,
                                                                      List<FileTemplate> templateList) {
        FileTemplateListResponse response = new FileTemplateListResponse();

        response.setTotalCount(totalCount);
        response.setTotalPage((int) Math.ceil(totalCount / (double) pageSize));

        templateList.forEach(item -> {
            item.setTemplateFile(FileConvert.fillFileBeanUrlPath(item.getTemplateFile()));
        });
        response.setTemplateList(templateList);
        return response;

    }

    public static FileTemplate fillFileTemplate(FileTemplate fileTemplate) {
        fileTemplate.setTemplateFile(FileConvert.fillFileBeanUrlPath(fileTemplate.getTemplateFile()));
        return fileTemplate;
    }

}
